package org.arithmetic.string;

import java.text.BreakIterator;
import java.util.Scanner;

/**
 * Created by LUOLIANG on 2016/9/1.
 * 把一个字符串的大写字母放到字符串的后面，各个字符的相对位置不变，且不能申请额外的空间。
 */
public class SplitBigToLast {

    public static void main(String[] args) {
        System.out.println("输入字符串：");
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            char[] c = s.toCharArray();
            int len = c.length;
            int d = 0;

            for (int i = 0; i < len - d; i++) {
                char tmp = 0;
                if (Character.isUpperCase(c[i])) {
                    tmp = c[i];
                    //循环前移
                    for (int j = i; j < len - 1; j++) {
                        c[j] = c[j + 1];
                    }
                    //把最后一个位置赋值
                    c[len - 1] = tmp;
                    d++;
                    i--;
                }
            }

            System.out.println(new String(c));
            if (!scanner.hasNextLine()) {
                break;
            }
        }
    }
}
